package cn.sms.quartz.service.impl;

import cn.sms.quartz.job.MainJob;
import cn.sms.quartz.service.IQuartzService;
import cn.sms.quartz.util.QuartzJobInfo;
import cn.sms.quartz.util.QuartzUtils;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;

@Service
public class QuartzServiceImpl implements IQuartzService {
    @Autowired
    private SchedulerFactoryBean schedulerFactoryBean;

    @Override
    public void addJob(QuartzJobInfo quartzJobInfo) {
        Scheduler sched = schedulerFactoryBean.getScheduler();
        String jobName = quartzJobInfo.getJobName();
        Class cls = MainJob.class;
        Object params = quartzJobInfo.getParams();
        String time = quartzJobInfo.getCronj();
        QuartzUtils.addJob(sched, jobName, cls, params, time);
    }
}
